#！/bin/bash

echo "固态硬盘优化"
echo "将常用的tmp目录挂载到内存中而不是硬盘上，优化固态硬盘的写入"
echo "同时每周执行一遍ftrim命令，优化文件系统"
echo
read -p "回车继续"

if [ -e /etc/fstab.bak ]; then
    cp /etc/fstab.bak /etc/fstab
fi

sed -i.bak 's/errors=remount-ro/noatime,nodiratime,errors=remount-ro/g' /etc/fstab
echo 'tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0' >> /etc/fstab
echo 'tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0' >> /etc/fstab
echo 'tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0' >> /etc/fstab
echo 'tmpfs /var/log/apt tmpfs defaults,noatime 0 0' >> /etc/fstab

echo '#!/bin/sh' > /etc/cron.weekly/fstrim
echo 'fstrim /' >> /etc/cron.weekly/fstrim
chmod +x /etc/cron.weekly/fstrim